unit ufrmReportDesigner;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ufrmBase, StdCtrls, ExtCtrls, RzSplit, Buttons, RzDBGrid,
  RMD_ReportExplorer, uPubDeclare, RM_DsgGridReport, RM_Designer,
  uDM, DB, ADODB, RM_Class, Grids, DBGrids, RzPanel, DosMove, Menus;

type
  TfrmReportDesigner = class(TfrmBase)
    rzszpnlSQL: TRzSizePanel;
    pnlData: TPanel;
    grpHeaderSQL: TGroupBox;
    grpDetailSQL: TGroupBox;
    grpHeaderData: TGroupBox;
    grpDetailData: TGroupBox;
    pnlButton: TPanel;
    btnRefresh: TBitBtn;
    btnReportModify: TBitBtn;
    mmoHeaderSQL: TMemo;
    mmoDetailSQL: TMemo;
    rzdbgrdHeaderData: TRzDBGrid;
    rzdbgrdDetailData: TRzDBGrid;
    RMReportExplorer: TRMReportExplorer;
    rmgrdrprtdsgnr1: TRMGridReportDesigner;
    rmdsgnr1: TRMDesigner;
    dsHeaderData: TDataSource;
    dsDetailData: TDataSource;

    procedure FormResize(Sender: TObject);
    procedure btnRefreshClick(Sender: TObject);
    procedure btnReportModifyClick(Sender: TObject);
  private
    { Private declarations }
  public

    fReportExplorer: TRMReportExplorer;
    { Public declarations }
    function CanOperate(AOperate: TOperateState): Boolean; override;
  end;

var
  frmReportDesigner: TfrmReportDesigner;

implementation

{$R *.dfm}

{ TfrmReportDesigner }

function TfrmReportDesigner.CanOperate(AOperate: TOperateState): Boolean;
begin
  Result := AOperate = mFormClose;
end;

procedure TfrmReportDesigner.FormResize(Sender: TObject);
begin
  inherited;
  grpHeaderSQL.Width := Trunc(rzszpnlSQL.Width / 2);
  grpHeaderData.Width := Trunc(pnlData.Width / 2);
end;

procedure TfrmReportDesigner.btnRefreshClick(Sender: TObject);
begin
  inherited;
  if Trim(mmoHeaderSQL.Text) <> '' then
  begin
    dm.adsReportHeader.Close;
    DM.adsReportHeader.CommandText := mmoHeaderSQL.Text;
    DM.adsReportHeader.Open;
  end;
  if Trim(mmoDetailSQL.Text) <> '' then
  begin
    DM.adsReportDetail.Close;
    DM.adsReportDetail.CommandText := mmoDetailSQL.Text;
    DM.adsReportDetail.Open;
  end;  
end;

procedure TfrmReportDesigner.btnReportModifyClick(Sender: TObject);
begin
  inherited;
  with RMReportExplorer do
  begin
    FolderDataSet := DM.adsReportFolder;
    ItemDataSet := DM.adsReportItems;
    GetReportDataSet := DM.adsReportBlod;
    Reports.Items[0].Report := DM.rmgrdrptReport;
    Reports.Items[1].Report := DM.rmrprtReport;
    Execute;
    end;
end;

initialization
  RegisterClass(TfrmReportDesigner);
end.
